<?php
namespace app\small\controller;
use Endroid\QrCode\QrCode;
use qrc\Aes;
use think\Controller;
use think\Db;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/12
 * Time: 16:43
 */
class Qrc extends Controller{
    public function Index(){
        $uid = input('uid');
        $iden = input('iden');
        $num = rand(0000,9999);
        //流水号
        $OutTradeNo = date('YmdHis',time()).$num;
        //小程序二维码
        $res=array(
            'uid'         => (int)$uid,
            'cardTime'    => time(),
            'iden'        => (int)$iden, //用户身份
            'type'        => 'post', //判断参数
            'OutTradeNo'  => (string)$OutTradeNo //订单流水号
        );
        $res = json_encode($res);
        $aes = new Aes('1234567812345678');
        //加密
        $encrypted = $aes->encrypt($res);
        $qrCode = new QrCode();
        ob_start();
        $qrCode ->setText($encrypted);
        //$qrCode  ->setSize(300);//大小
        $qrCode ->setLabelFontPath(VENDOR_PATH.'endroid/qrcode/assets/fonts/noto_sans.otf');
        $qrCode ->setErrorCorrectionLevel('high');
        $qrCode ->setLabelFontSize(16);
        header('Content-Type: '.$qrCode->getContentType());
        $png = $qrCode->writeString();
        $imageString = base64_encode($png);
        ob_end_clean();
        return 'data:image/png;base64,'.$imageString;
        //return '<img src="data:image/png;base64,'.$imageString.'">';
    }
}